package org.springframework.cloud.openfeign;

import cn.hill4j.tool.spring.ext.feign.wrap.WrapTarget;
import cn.hill4j.tool.spring.ext.feign.wrap.FeignUrlSupplier;
import feign.Feign;
import feign.Target;

/**
 * ClassName: DymUrlTargeter
 * Description: TODO
 *
 * @author hillchen
 * Date: 2023年08月13日
 * @version: 1.0
 */
public class WrapUrlTargeter implements Targeter{
    private FeignUrlSupplier feignUrlSupplier;

    public WrapUrlTargeter(FeignUrlSupplier feignUrlSupplier) {
        this.feignUrlSupplier = feignUrlSupplier;
    }

    @Override
    public <T> T target(FeignClientFactoryBean factory, Feign.Builder feign, FeignContext context, Target.HardCodedTarget<T> target) {
        Target<T> dymTarget = new WrapTarget<>(target.type(), target.name(), () -> feignUrlSupplier.getUrl(target));
        return feign.target(dymTarget);
    }
}
